<?php
class Appointment extends AppModel {

	var $name = 'Appointment';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
			'User' => array('className' => 'User',
								'foreignKey' => 'user_id',
								'conditions' => '',
								'fields' => 'username, id',
								'order' => ''
			),
			'Doctor' => array('className' => 'User',
								'foreignKey' => 'doctor_id',
								'conditions' => '',
								'fields' => 'username, id',
								'order' => ''
			),
			'Specialty' => array('className' => 'Specialty',
								'foreignKey' => 'specialty_id',
								'conditions' => '',
								'fields' => 'name',
								'order' => ''
			),
	);
	function afterFind($results, $primary=false) {
    	if($primary == true) {
    	   if(Set::check($results, '0.0')) {
    	      $fieldName = key($results[0][0]);
    	       foreach($results as $key=>$value) {
    	          $results[$key][$this->alias][$fieldName] = $value[0][$fieldName];
    	          unset($results[$key][0]);
    	       }
    	    }
    	}	

    	return $results;
	}
}
?>